<UserControl x:Class="MathematicallySafe.HeadCounter.Views.RaidImportView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:commands="clr-namespace:MathematicallySafe.HeadCounter.Commands"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModels="clr-namespace:MathematicallySafe.HeadCounter.ViewModels"
    Initialized="RaidImportViewInitialized"
    IsVisibleChanged="RaidImportViewIsVisibleChanged"
    AllowDrop="True" Drop="RaidImportViewDrop">
    
    <UserControl.Resources>
      
        <commands:CommandReference x:Key="PasteRaidCommandReference" Command="{Binding PasteRaidCommand}"/>
          
        <DataTemplate x:Key="IgnoreCellTemplate">
          <CheckBox HorizontalAlignment="Center" IsChecked="{Binding Path=Ignore}"/>
        </DataTemplate>
          
        <DataTemplate x:Key="HeadCountRaiderNameCellTemplate">
          <StackPanel Orientation="Horizontal">
                    <Rectangle Style="{StaticResource ClassGlyph}" />
                    <TextBlock Style="{StaticResource KeyDataTextStyle}" Text="{Binding Path=Name}" />
                    <TextBlock Style="{StaticResource HighlightedDataTextStyle}" Text="(New)" 
                               Visibility="{Binding Path=IsNewRaider, Converter={StaticResource CollapsedIfFalse}}" />
          </StackPanel>
        </DataTemplate>
          
        <DataTemplate x:Key="RaidTimeCellTemplate">
            <TextBlock Style="{StaticResource NumericDataTextStyle}" Text="{Binding Path=ActualTime.TotalMinutes, StringFormat=0}">
                <TextBlock.ToolTip>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Margin="2,2,0,2" Text="{Binding Path=TotalTime.TotalMinutes, StringFormat=Total : 0}" />
                        <TextBlock Margin="4,2,0,2" Text="{Binding Path=WaitTime.Minutes, StringFormat=Wait : 0}"/>
                        <TextBlock Margin="4,2,0,2" Text="{Binding Path=Offline.Minutes, StringFormat=Offline : 0}"/>
                    </StackPanel>
                </TextBlock.ToolTip>
            </TextBlock>
        </DataTemplate>
          
        <DataTemplate x:Key="LootCellTemplate">
            <StackPanel>
                <TextBlock Visibility="{Binding Path=Downloading, Converter={StaticResource CollapsedIfFalse}}">Downloading item...</TextBlock>
                    <TextBlock Visibility="{Binding Path=Downloading, Converter={StaticResource CollapsedIfTrue}}">
                    <Hyperlink TextDecorations="None" NavigateUri="{Binding LootUri}" RequestNavigate="HyperlinkOnRequestNavigate">
                        <TextBlock Style="{StaticResource EpicItemDataTextStyle}" Text="{Binding Path=Name}" />
                    </Hyperlink>
                </TextBlock>
            </StackPanel>
        </DataTemplate>
          
        <DataTemplate x:Key="LootWinnerCellTemplate">
          <TextBlock Style="{StaticResource KeyDataTextStyle}" Text="{Binding Path=LooterName}"/>
        </DataTemplate>

    </UserControl.Resources>
    
    <UserControl.InputBindings>
        <KeyBinding Key="V" Command="{StaticResource PasteRaidCommandReference}" Modifiers="Control"/>
    </UserControl.InputBindings>

    <Grid Style="{StaticResource TabContainer}">

        <Grid Visibility="{Binding Path=IsImportingRaid, Converter={StaticResource CollapsedIfFalse}}" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0" >
                <TextBlock Style="{StaticResource SectionTitle}" Text="{Binding Path=HeadCountRaid.Description}" VerticalAlignment="Center"/>
                <CheckBox VerticalAlignment="Center" IsChecked="{Binding Path=HeadCountRaid.Optional}">Optional</CheckBox>
            </StackPanel>

            <ListView Name="listViewRaiders" Grid.Row="1" Grid.Column="0" 
                      ItemContainerStyle="{StaticResource ListViewItemStyle}" ItemsSource="{Binding Path=HeadCountRaid.Raiders}" >
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="75" CellTemplate="{StaticResource IgnoreCellTemplate}" Header="Ignore"/>
                        <GridViewColumn Width="NaN" CellTemplate="{StaticResource HeadCountRaiderNameCellTemplate}" Header="Raider"/>
                        <GridViewColumn Width="75" CellTemplate="{StaticResource RaidTimeCellTemplate}" Header="Time"/>
                    </GridView>
                </ListView.View>
            </ListView>

            <ListView Name="listViewLoot" Grid.Row="1" Grid.Column="1" 
                      ItemContainerStyle="{StaticResource ListViewItemStyle}" ItemsSource="{Binding Path=HeadCountRaid.Loot}" >
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="75" CellTemplate="{StaticResource IgnoreCellTemplate}" Header="Ignore"/>
                        <GridViewColumn Width="NaN" CellTemplate="{StaticResource LootCellTemplate}" Header="Loot"/>
                        <GridViewColumn Width="NaN" CellTemplate="{StaticResource LootWinnerCellTemplate}" Header="Winner"/>
                    </GridView>
                </ListView.View>
            </ListView>

            <StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="0,16,0,0" HorizontalAlignment="Right" VerticalAlignment="Bottom">
                <TextBlock Style="{StaticResource ErrorMessage}" Text="{Binding ValidationMessage}" Visibility="{Binding IsRaidValid, Converter={StaticResource CollapsedIfTrue}}" />
                <Button Margin="4,2" Command="{Binding Path=ImportRaidCommand}">Import</Button>
                <Button Margin="4,2" Command="{Binding Path=CancelRaidImportCommand}">Cancel</Button>
            </StackPanel>
        </Grid>

        <TextBlock Visibility="{Binding Path=IsImportingRaid, Converter={StaticResource CollapsedIfTrue}}" 
               Style="{StaticResource LargeInstructionText}" Text="Drop or Paste (Ctrl-V) HeadCount data here" />

    </Grid>

</UserControl>